/*
 * HttpProtocol.h
 *
 */

#ifndef HTTPPROTOCOL_H_
#define HTTPPROTOCOL_H_

#include "HttpRequest.h"
#include "HttpResponse.h"
#include "../../common/Socket.h"
#include <vector>


class HttpProtocol {
	private:
		static const int BODY_BUFFER_SIZE = 512;
		Socket& socket;
		std::vector<char> bodyBuffer;
		HttpRequest* request;
	public:
		HttpProtocol(Socket& socket);
		virtual ~HttpProtocol();

		const HttpRequest* recvRequest();
		void sendResponse(HttpResponse& response);
	protected:
		void recvLine(std::string& line);
		void recvHeaders(HttpRequest* request);
		void recvBody(HttpRequest* request, size_t size);

		void sendLine(const std::string& line);
		void sendHeaders(HttpResponse& response);
		void sendBody(HttpBody& body);

		void setRequest(HttpRequest* request);
};

#endif /* HTTPPROTOCOL_H_ */
